//
//  BaseViewController.m
//  联付商圈
//
//  Created by 于洋 on 2017/7/14.
//  Copyright © 2017年 lianfu. All rights reserved.
//
#import "联付商圈-Swift.h"
#import "BaseViewController.h"

@interface BaseViewController ()

@end

@implementation BaseViewController

- (void)dealloc
{
    self.activeTextView = nil;
    self.activeTextField = nil;
    self.activeScrollView = nil;
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    if (self.observeKeyboard) {
        [self registerForKeyboardNotifications];
    }
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.view endEditing:YES];
    
    if (self.observeKeyboard) {
        [self unregisterForKeyboardNotifications];
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor]}];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBar.tintColor = [UIColor blackColor];
    
    [self prepareData];

}

- (void)prepareData {}

- (void)reloadView {}

- (void)refreshView {}

- (void)popViewController {
    if (self.navigationController) {
        [self.navigationController popViewControllerAnimated:YES];
    }
}

- (UILabel *)makeLabelWithText:(NSString *)text
                          Font:(UIFont *)font
                     TextColor:(UIColor *)textColor
                 TextAlignment:(NSTextAlignment)textAlignment
{
    UILabel *label = [[UILabel alloc] init];
    label.text = text;
    label.font = font;
    label.textColor = textColor;
    label.textAlignment = textAlignment;
    return label;
}

- (CGFloat)calculateRowWidth:(NSString *)string
                    FontSize:(NSInteger)fontSize
                      Height:(CGFloat)height
{
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:fontSize * FONTSIZE]};  //指定字号
    CGRect rect = [string boundingRectWithSize:CGSizeMake(0, height)/*计算宽度时要确定高度*/ options:NSStringDrawingUsesLineFragmentOrigin |
                   NSStringDrawingUsesFontLeading attributes:dic context:nil];
    return rect.size.width;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark - keyboard Show or Hide

- (void)registerForKeyboardNotifications
{
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillShow:)
                                                 name:UIKeyboardDidShowNotification object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillHide:)
                                                 name:UIKeyboardWillHideNotification object:nil];
}

- (void)unregisterForKeyboardNotifications
{
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:UIKeyboardWillHideNotification
                                                  object:nil];
    
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:UIKeyboardDidShowNotification
                                                  object:nil];
}

- (void)keyboardWillShow:(NSNotification *)notification {
    NSLog(@"______________________");
}

- (void)keyboardWillHide:(NSNotification *)notification {
    
}

@end
